package com.laoye.controller;

import com.laoye.bean.Address;
import com.laoye.bean.Order;
import com.laoye.mapper.AddressMapper;
import com.laoye.service.AddressService;
import com.laoye.service.OrderService;
import com.laoye.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/address")
public class AddressController {
    @Autowired
    AddressService addressService;

    /**
     * 新增 地址
     * @param address 前端传递的参数
     * @return 添加结果
     */
    @PostMapping("/addAddress")
    public Result<String> addOrder(@RequestBody Address address) {
         addressService.addAddress(address);
        return Result.success("新地址添加成功");
    }
/**
     * 获取 地址列表
     * @return 地址列表
     */
    @GetMapping("/addressList")
    public Result<List<Address>> addressList() {
        return Result.success(addressService.addressList());
    }
/**
     * 获取 地址
     * @return 地址
     */
    @GetMapping("/getAddress")
    public Result<Address> getAddress() {
        return Result.success(addressService.getAddress());
    }
/**
     * 修改 地址
     * @param address 前端传递的参数
     * @return 修改结果
     */
    @PutMapping("/editAddress")
    public Result<String> editAddress(@RequestBody Address address) {
         addressService.editAddress(address);
        return Result.success("地址信息修改成功");
    }
/**
     * 删除 地址
     * @param id 地址id
     * @return 删除结果
     */
    @DeleteMapping("/deleteAddress/{id}")
    public Result<String> deleteAddress(@PathVariable("id") Integer id) {
        addressService.deleteAddress(id);
        return Result.success("地址信息删除成功");
    }
}
